package com.keta.foundation.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.keta.foundation.dao.LogInfoDAO;
import com.keta.foundation.entity.LogInfo;
import com.keta.foundation.entity.Module;
import com.keta.foundation.service.LogInfoService;
import com.keta.foundation.service.UserRoleService;
import com.keta.foundation.util.dwz.Page;
import com.keta.foundation.util.dwz.PageUtil;

@Service
@Transactional
public class LogInfoServiceImpl implements LogInfoService {

	@Autowired
	private LogInfoDAO logInfoDAO;

	@Override
	public void save(LogInfo logInfo) {
		logInfoDAO.saveAndFlush(logInfo);
	}

	@Override
	public List<LogInfo> getAll() {
		return logInfoDAO.findAll();
	}

	@Override
	public List<LogInfo> getAll(Page page) {
		org.springframework.data.domain.Page<LogInfo> springPage = logInfoDAO.findAll(PageUtil.createPageable(page));
		page.setTotalPage(springPage.getTotalPages());
		page.setTotalCount(springPage.getTotalElements());
		return springPage.getContent();
	}

	@Override
	public List<LogInfo> getAll(Specification<LogInfo> specification, Page page) {
		org.springframework.data.domain.Page<LogInfo> springPage = logInfoDAO.findAll(specification,
				PageUtil.createPageable(page));
		page.setTotalPage(springPage.getTotalPages());
		page.setTotalCount(springPage.getTotalElements());
		return springPage.getContent();
	}

	@Override
	public void delete(Long id) {
		logInfoDAO.delete(id);
	}

}
